﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class orderroom : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["pm"] = null;
        DataSet ds = new DataSet();
        ds = func.dispic(DropDownList1.SelectedValue);
        Image1.ImageUrl = ds.Tables[0].Rows[0][1].ToString();
        ds.Clear();
        ds = func.ERoomInfor(DropDownList1.SelectedValue);
        if (ds.Tables[0].Rows.Count >= 1)
        {
            Session["pm"] = ds.Tables[0].Rows[0][4].ToString();
            func.GridViewDataBind(GridView1, ds.Tables[0]);
            DropDownList2.DataSource = ds.Tables[0];
            DropDownList2.DataTextField = "HM_RCategoryId";
            DropDownList2.DataBind();
        }
        else
        {
            Response.Write("<script>alert('无数据，请选择其他的')</script>");
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["pm"] = null;
        DataSet ds = new DataSet();
        ds = func.dispic(DropDownList1.SelectedValue);
        Image1.ImageUrl = ds.Tables[0].Rows[0][1].ToString();
        ds.Clear();
        ds = func.ERoomInfor(DropDownList1.SelectedValue);
        if (ds.Tables[0].Rows.Count>=1)
        {
            Session["pm"] = ds.Tables[0].Rows[0][4].ToString();
            func.GridViewDataBind(GridView1, ds.Tables[0]);
            DropDownList2.DataSource = ds.Tables[0];
            DropDownList2.DataTextField = "HM_RCategoryId";
            DropDownList2.DataBind();
        }
        else
        {
            Response.Write("<script>alert('无数据，请选择其他的')</script>");
        }
        
    }


    //protected void Button1_Click(object sender, EventArgs e)
    //{
    //    DataSet ds = new DataSet();
    //    ds = func.ERoomInfor(DropDownList1.SelectedValue);
    //    GridView1.DataSource = ds;
    //    GridView1.DataBind();
    //    DropDownList2.DataTextField = "HM_RCategoryId";
    //    DropDownList2.DataBind();
    //}

    protected void btn_Click(object sender, EventArgs e)
    {
        if(Session["usr"]==null)
        {
            Response.Write("<script>alert('您还未登录登陆，正在前往登陆页面');location.href='login.aspx';</script>");

        }
        else
        {
            if(func.isordinfor(Session["usr"].ToString()))
            {
                Response.Write("<script>alert('您已经订购，退房后重试');location.href='user_func.aspx';</script>");

            }
            else
            {

                if (!func.isinfor(Session["usr"].ToString()))
                {
                    Response.Write("<script>alert('您还没有完善信息，正在跳转完善信息页面');location.href='add_user_infor.aspx';</script>");
                }
                else
                {
                    if (func.updstatus(int.Parse(DropDownList2.SelectedValue), 0))
                    {
                        if (func.updroominfor(Session["usr"].ToString(), 0, int.Parse(DropDownList2.SelectedValue), DropDownList1.SelectedValue, int.Parse(Session["pm"].ToString()), 0))
                        {
                            Response.Write("<script>alert('订房成功，正在前往订房信息页面');location.href='search_room_infor.aspx';</script>");

                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('订房失败，请稍后再试')'</script>");

                    }
                }
               
            }
        }
    }

   
}